|
|
|
|
|
|
|
Figure 3.2
Program CopyDDB uses an array of RGBTriplet
values to manipulate a bitmap. |
|
|
|
|
|
|
|
|
When a program does not need to examine and modify many pixels in an image, the differences in speed are not as dramatic. Drawing lines or circles using Visual Basic's Line and Circle methods is faster than individually setting the pixels needed to draw these shapes using GetBitmapBits and SetBitmapBits. |
|
|
|
|
|
|
|
|
Device-Independent Bitmaps |
|
|
|
|
|
|
|
|
In an attempt to bring order to chaos, Microsoft created device-independent bitmaps (DIBs). A DIB is basically a data structure that contains the pixel information needed to produce an image at a certain color depth. For example, an 8-bit color depth DIB contains a color table listing the 256 colors used by the image. Keeping the color information in the DIB makes it somewhat easier to display the image at different color resolutions. |
|
|
|
|
|
|
|
|
Despite its name, a DIB is really not very device independent. As is the case with devicedependent bitmaps, DIBs of different color depths are different. A DIB with 1-, 4-, or 8-bit color includes a color table. DIBs that use more than 8 bits per pixel contain the pixels' color component values instead. While DIBs make some operations easier, they do not solve every color problem. |
|
|
|
|
|
|
|
|
A DIB is described by a BITMAPINFO data structure. The first part of this structure is a BITMAPINFOHEADER data structure that defines certain characteristics of the DIB. |
|
|
|
|
|
|
|
|
The second part of the BITMAPINFO structure contains the color table used by the DIB. A DIB with a color depth of eight or less includes entries here. A DIB with a higher color resolution does not have a color table. Because the largest color table a program might need holds 256 entries, you can declare the BITMAPINFO data type to include 256 color table entries. The DIB functions will not use all of these entries if the image does not need them, but that does little harm. You will just allocate a little more memory than necessary. |
|
|
|
|
|